package ljl.codetop300;

import commons.TreeNode;

public class _offer_26_sub_structure {

  /**
   * 和子树差不多，可以说是基本一样
   */
  public boolean isSubStructure(TreeNode A, TreeNode B) {
    if (A == null || B == null) return false;
    return yes(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
  }
  boolean yes(TreeNode A, TreeNode B) {
    if (A == null) return B == null;
    if (B == null) return true;
    return A.val == B.val && yes(A.left, B.left) && yes(A.right, B.right);
  }

}
